package com.shxc.smarttrade.old.presenter;

import android.os.Handler;

import com.shxc.smarttrade.old.bean.MasterCopyInfo;
import com.shxc.smarttrade.old.iview.SupermandetailIView;
import com.shxc.smarttrade.old.modal.IRequestServiceListener;
import com.shxc.smarttrade.old.modal.MasterDetailModal;

/**
 * Created by jcdev1 on 2017/9/28.
 */

public class MasterDetailPresenter {
    private SupermandetailIView supermandetailIView;
    private MasterDetailModal masterDetailModal;
    private Handler handler = new Handler();

    public MasterDetailPresenter(SupermandetailIView supermandetailIView) {
        this.supermandetailIView = supermandetailIView;
        this.masterDetailModal = new MasterDetailModal();
    }

    /**
     * 获取跟随高手金额信息
     *
     * @param accessToken
     * @param usweId
     * @param userCode
     */
    public void getMasterCopyInfo(String accessToken, int usweId, String userCode) {

        masterDetailModal.getMasterCopyInfo(accessToken, usweId, userCode, new IRequestServiceListener() {
            @Override
            public void success(final Object result) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        supermandetailIView.showMasterCopyInfo((MasterCopyInfo.DataBean.CopyInfoBean) result);
                    }
                });
            }

            @Override
            public void faild(final String msg) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        supermandetailIView.showMyToast(msg);
                    }
                });
            }
        });
    }


    /**
     * 跟随高手
     *
     * @param accessToken
     * @param userId
     * @param userCode
     * @param amt
     */
    public void copyMaster(String accessToken, int userId, String userCode, String amt, int tag) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                supermandetailIView.showDialog();
            }
        });
        masterDetailModal.copyMaster(accessToken, userId, userCode, amt, tag, new IRequestServiceListener() {
            @Override
            public void success(final Object result) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        supermandetailIView.dismissDialog();
                        supermandetailIView.showMasterCopyMasterResult((String) result);
                    }
                });
            }

            @Override
            public void faild(final String msg) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        supermandetailIView.dismissDialog();
                        supermandetailIView.showMyToast(msg);
                    }
                });
            }
        });
    }

    /**
     * 取消跟随高手
     *
     * @param accessToken
     * @param userId
     * @param userCode
     * @param isClose
     */
    public void cancelMasterCopy(String accessToken, int userId, String userCode, int isClose) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                supermandetailIView.showDialog();
            }
        });
        masterDetailModal.cancelMasterCopy(accessToken, userId, userCode, isClose, new IRequestServiceListener() {
            @Override
            public void success(final Object result) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        supermandetailIView.dismissDialog();
                        supermandetailIView.showMasterCancleCopyResult((String) result);
                    }
                });
            }

            @Override
            public void faild(final String msg) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        supermandetailIView.dismissDialog();
                        supermandetailIView.showMyToast(msg);
                    }
                });
            }
        });
    }
}
